home *** CD-ROM | disk | FTP | other *** search
- /*
- * Log application (for re-authenticating to the AFP server under AFS)
- */
- /*
- * Copyright (c) 1990 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appears in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation, and that the name of
- * The University of Michigan not be used in advertising or
- * publicity pertaining to distribution of the software without
- * specific, written prior permission. This software is supplied as
- * is without expressed or implied warranties of any kind.
- *
- * ITD Research Systems
- * University of Michigan
- * 535 W. William Street
- * Ann Arbor, Michigan
- * +1-313-936-2652
- * netatalk@terminator.cc.umich.edu
- */
- #include <types.h>
- #include <errors.h>
- #include <resources.h>
- #include <quickdraw.h>
- #include <fonts.h>
- #include <events.h>
- #include <windows.h>
- #include <menus.h>
- #include <textedit.h>
- #include <dialogs.h>
- #include <memory.h>
- #include <osutils.h>
- #include <osevents.h>
- #include <segload.h>
- #include <strings.h>
- #include <fcntl.h>
- #include <files.h>
- #include <appletalk.h>
- #include <toolutils.h>
- #include <traps.h>
- #include <desk.h>
- #include <devices.h>
- #include <lists.h>
- #include <traps.h>
- #include <cursorctl.h>
-
- #include <conf.h>
- #include <des.h>
- #include <krb.h>
- #include "uam.h"
- #include "log.h"
- #include "rsrc.h"
-
- short doDRVROpen( CntrlParam *ctlPB, DCtlPtr dCtl );
- pascal Boolean selectfilter();
- short findsessions( struct sesslist *sl, short resid );
- short selectdialog( struct sesslist *sl, int n, short resid );
- pascal void drawlist( DialogPtr dlog, short item );
- void setname( struct sesslist *slp, Str255 vol, short width );
-
- extern char afp_server[];
-
- pascal short
- DRVROpen( ctlPB, dCtl )
- CntrlParam *ctlPB;
- DCtlPtr dCtl;
- {
- short rc;
- Ptr mem;
- long old_A5, new_A5;
-
- /*
- * initialize area off A5 for globals
- */
- if (( mem = NewPtr( A5Size())) == NULL ) {
- return( -1 );
- }
- mysetup_A5( mem, &new_A5 );
- old_A5 = SetA5( new_A5 );
- mysetup_QD( old_A5 );
-
- /*
- * open our DA (and do all the work!)
- */
- rc = doDRVROpen( ctlPB, dCtl );
-
- /*
- * clean up A5 area
- */
- myrestore_A5( old_A5 );
- DisposPtr( mem );
- return( rc );
- }
-
-
- short
- doDRVROpen( ctlPB, dCtl )
- CntrlParam *ctlPB;
- DCtlPtr dCtl;
- {
- struct sesslist *slist;
- short resid;
- GrafPtr oldport;
- char name[ MAXNAMELEN + 1 ], passwd[ MAXPASSWDLEN + 1 ], *buf;
- AFPLoginPrm alp;
- short nsessions, srefnum, rf, off;
- Boolean dosetpw;
- int sess;
- Handle iconhdl;
- DialogPtr dlog;
- SysEnvRec senv;
- des_cblock sesskey;
- acurHandle acur_hdl;
-
- /*
- * ignore multiple opens....
- */
- if ( dCtl->dCtlWindow != NULL ) {
- return( noErr );
- }
-
- if (( slist = (struct sesslist *)NewPtr( MAX_SESSIONS * sizeof( struct sesslist ))) == NULL ) {
- return( -1 );
- }
-
- GetPort( &oldport );
- resid = OWNEDRSRCID(dCtl->dCtlRefNum);
- InitCursor();
-
- /*
- * check ROM revision
- */
- SysEnvirons( 1, &senv );
- if ( senv.machineType < 0) {
- doalert( resid + ALRT_BADROM );
- SetPort( oldport );
- DisposPtr( (Ptr)slist );
- HUnlock( (Handle)acur_hdl );
- ReleaseResource( (Handle)acur_hdl );
- return( -1 );
- }
- if (( rf = HOpenResFile( senv.sysVRefNum, 0,
- "\p:AppleShare Folder:AFS Kerberos", fsRdPerm )) < 0 ) {
- doalert( resid + ALRT_FILEERR );
- SetPort( oldport );
- DisposPtr( (Ptr)slist );
- HUnlock( (Handle)acur_hdl );
- ReleaseResource( (Handle)acur_hdl );
- return( -1 );
- }
-
- nsessions = findsessions( slist, resid );
- if ( nsessions <= 0 ) {
- CloseResFile( rf );
- SetPort( oldport );
- DisposPtr( (Ptr)slist );
- HUnlock( (Handle)acur_hdl );
- ReleaseResource( (Handle)acur_hdl );
- return( -1 );
- }
-
- name[ 0 ] = 0;
-
- if (( acur_hdl = (acurHandle)Get1Resource( 'acur', ACUR_WATCH )) == NULL ) {
- return( -1 );
- }
- HLock( (Handle)acur_hdl );
- InitCursorCtl( acur_hdl );
-
- while( 1 ) {
- sess = 0;
- if ( nsessions > 1 && ( sess = selectdialog( slist, nsessions, resid )) < 0 ) {
- break;
- }
-
- srefnum = slist[ sess ].sess_refnum;
- bcopy( slist[ sess ].sess_name + 1, afp_server + 1, slist[ sess ].sess_namelen );
- afp_server[ 0 ] = slist[ sess ].sess_namelen;
- ParamText( NULL, afp_server, NULL, NULL );
-
- bzero( (char*)&alp, sizeof( AFPLoginPrm ));
- if ( OpenXPP( &alp.ioRefNum ) != noErr ) {
- doalert( ALRT_LOCALERR );
- break;
- }
- if ( get_server_status( alp.ioRefNum, slist[ sess ].sess_addr,
- &iconhdl, &dosetpw ) != 0 ) {
- DisposPtr( (Ptr)slist );
- HUnlock( (Handle)acur_hdl );
- ReleaseResource( (Handle)acur_hdl );
- return( -1 );
- }
-
- /*
- * perform the password dialog
- */
- dlog = passwddialog( name, passwd, iconhdl, resid + LOG_PASSWD_DLOG,
- false, srefnum, dosetpw );
- if ( iconhdl != NULL ) {
- DisposHandle( iconhdl );
- }
-
- if ( dlog != NULL ) {
- alp.aspTimeout = 3; /* kind of arbitrary! */
- alp.ioCompletion = NULL;
-
- if ( dologin( false, true, &alp, name, passwd, &srefnum, sesskey ) == noErr ) {
- doalert( resid + ALRT_AUTHOK );
- }
- DisposDialog( dlog );
- } else {
- if ( nsessions == 1 ) {
- break;
- }
- }
- }
- CloseResFile( rf );
- SetPort( oldport );
- DisposPtr( (Ptr)slist );
- HUnlock( (Handle)acur_hdl );
- ReleaseResource( (Handle)acur_hdl );
- return( -1 );
- }
-
-
-
- pascal short
- DRVRPrime( ctlPB, dCtl )
- CntrlParam *ctlPB;
- DCtlPtr dCtl;
- {
-
- return( noErr ); /* Not used in this desk accessory */
- }
-
- pascal short
- DRVRStatus( ctlPB, dCtl )
- CntrlParam *ctlPB;
- DCtlPtr dCtl;
- {
- return( noErr ); /* Not used in this desk accessory */
- }
-
-
- pascal short
- DRVRControl( ctlPB, dCtl )
- CntrlParam *ctlPB;
- DCtlPtr dCtl;
- {
- EventRecord evt;
-
- extern void doCtlEvent();
- extern void doPeriodic();
-
- switch (ctlPB->csCode) {
- case accEvent:
- /*
- HLock(dCtl->dCtlStorage);
- doCtlEvent( *((EventRecord **) &ctlPB->csParam[0]),
- (Globals *)(*dCtl->dCtlStorage), dCtl->dCtlRefNum, dCtl->dCtlWindow );
- HUnlock(dCtl->dCtlStorage);
- */
- break;
-
- case accRun: /* periodicEvent */
- /*
- doPeriodic(dCtl);
- */
- break;
-
- case accCursor: /* null event to blink cursor */
- /*
- evt.message = 0;
- DialogSelect( &evt, NULL, NULL );
- */
- break;
-
- }
- return( noErr );
- }
-
- #ifdef notdef
- void
- doCtlEvent(register EventRecord *theEvent, Globals *globals, short refnum, DialogPtr dlog)
- {
- char name[ 64 ], passwd[ 64 ];
- short item;
- DialogPtr adlog;
-
- }
- #endif notdef
-
- pascal short
- DRVRClose( ctlPB, dCtl)
- CntrlParam *ctlPB;
- DCtlPtr dCtl;
- {
- return( noErr );
- }
-
-
- short
- findsessions( sl, resid )
- struct sesslist sl[];
- short resid;
- {
- AVCB *vcbp;
- HParamBlockRec hpb;
- GetVolParmsInfoBuffer gvpi;
- ParamBlockRec pb;
- int i, j;
- short listwidth, item, rc;
- Rect r;
- long bufsize;
- unsigned char uamused;
- Ptr vinfobuf;
- VolumeType voltype;
- unsigned char volname[ 28 ], *p, *q;
- unsigned char where[ 1 + 32 + 4 + 32 ]; /* room for "Server in Zone" */
- short sessrefnum;
-
- listwidth = LIST_RIGHT - LIST_LEFT - 17;
-
- /*
- * form a list of remote sessions (by searching volume control blocks)
- */
- vcbp = (AVCB *)GetVCBQHdr()->qHead;
- i = 0;
- do {
- bzero( (char *)&hpb, sizeof( hpb ));
- hpb.ioParam.ioVRefNum = vcbp->vcbVRefNum;
- hpb.ioParam.ioBuffer = (Ptr)&gvpi;
- hpb.ioParam.ioReqCount = sizeof( gvpi );
- /* DebugStr( "\pabout to PBHGetVolParms" ); */
- if ( PBHGetVolParms( &hpb, false ) != noErr ) {
- continue;
- }
-
- if ( ( 1 << bHasExtFSVol ) & gvpi.vMAttrib ) { /* external volume */
- /* DebugStr( "\pexternal volume" ); */
- bzero( (char *)&pb, sizeof( pb ));
- pb.ioParam.ioVRefNum = vcbp->vcbVRefNum;
- pb.ioParam.ioBuffer = (Ptr)&bufsize;
- /* DebugStr( "\pabout to PBHGetVolMountInfoSize" ); */
- if (( rc = PBGetVolMountInfoSize( &pb )) != noErr && rc != paramErr ) {
- continue;
- }
-
- if ( rc == noErr ) {
- bufsize >>= 16; /* size is in upper 16 bits? XXX */
- if (( vinfobuf = NewPtr( bufsize )) == NULL ) {
- doalert( resid + ALRT_NOMEMORY );
- return( -1 );
- }
- bzero( (char *)&pb, sizeof( pb ));
- pb.ioParam.ioVRefNum = vcbp->vcbVRefNum;
- pb.ioParam.ioBuffer = vinfobuf;
- /* DebugStr( "\pabout to PBHGetVolMountInfo" ); */
- if (( rc = PBGetVolMountInfo( &pb )) != noErr ) {
- DisposPtr( vinfobuf );
- continue;
- }
- uamused = ((AFPVolMountInfo *)vinfobuf)->uamType;
- voltype = ((VolMountInfoHeader *)vinfobuf)->media;
-
- /*
- * copy volume name
- */
- p = (char *)vinfobuf + ((AFPVolMountInfo *)vinfobuf)->volNameOffset;
- bcopy( p, volname, *p + 1 );
-
- /*
- * create "Server in Zone" string
- */
- p = (char *)vinfobuf + ((AFPVolMountInfo *)vinfobuf)->serverNameOffset;
- q = where;
- bcopy( p, q, *p + 1 );
- q += ( *p + 1 );
- bcopy( " in ", q, 4 );
- q += 4;
- p = (char *)vinfobuf + ((AFPVolMountInfo *)vinfobuf)->serverNameOffset;
- bcopy( p, q, *p + 1 );
- DisposPtr( vinfobuf );
- } else {
- /* DebugStr( "\pusing old kludgy check for AFS login" ); */
- /*
- * mount calls not supported; try using undocumented "old" method
- */
- if ( GetPtrSize( (Ptr)vcbp ) != sizeof( AVCB )) {
- doalert( resid + ALRT_BADVERS );
- return( -1 );
- }
- uamused = vcbp->vcbLoginMethod;
- voltype = AppleShareMediaType; /* assumed */
- bcopy( vcbp->vcbVN, volname, sizeof( volname ));
- bcopy( vcbp->vcbFindWhere + 14, /* undocumented field XXX */
- where + 1, *vcbp->vcbFindWhere - 13 );
- where[ 0 ] = *vcbp->vcbFindWhere - 13;
- }
-
- if ( voltype != AppleShareMediaType && uamused != UAM_LOGINCODE ) {
- continue;
- }
- sessrefnum = vcbp->vcbSRefNum; /* undocumented field XXX */
-
- for ( j = 0; j < i; ++j ) {
- if ( sl[ j ].sess_refnum == sessrefnum ) {
- setname( &sl[ j ], volname, listwidth );
- break;
- }
- }
- if ( j == i ) {
- bzero( sl[ i ].sess_name, 256 );
- bcopy( where, sl[ i ].sess_name, 1 + where[ 0 ] );
- sl[ i ].sess_namelen = 1 + where[ 0 ];
- sl[ i ].sess_refnum = sessrefnum;
- bcopy( (char *)&gvpi.vMServerAdr, (char *)&sl[ i ].sess_addr, sizeof( long ));
- strcat( sl[ i ].sess_name + 1, " (" );
- sl[ i ].sess_name[ 0 ] += 2;
- sl[ i ].sess_namestate = 0;
- setname( &sl[ i ], volname, listwidth );
- ++i;
- }
- }
- } while ( i < MAX_SESSIONS && ( vcbp = (AVCB *)vcbp->qLink ) != 0 );
-
- if ( i < 1 ) {
- doalert( resid + ALRT_NOSERVERS );
- return( -1 );
- }
-
- return( i );
- }
-
- void
- setname( slp, vol, width )
- struct sesslist *slp;
- Str255 vol;
- short width;
- {
- char *p;
-
- p = slp->sess_name + slp->sess_name[ 0 ];
-
- if ( StringWidth( slp->sess_name ) + StringWidth( vol ) +
- StringWidth( "\p, ..." ) < width ) {
- if ( slp->sess_namestate == 0 ) {
- slp->sess_namestate = 1;
- p++;
- } else {
- *p++ = ',';
- }
- strncpy( p, vol + 1, *vol );
- p += *vol;
- *p = ')';
- slp->sess_name[ 0 ] += *vol + 1;
- } else if ( slp->sess_namestate != 2 ) {
- strncpy( p, ", ...)", 6 );
- slp->sess_name[ 0 ] += 5;
- slp->sess_namestate = 2;
- }
- }
-
- short
- selectdialog( sl, n, resid )
- struct sesslist sl[];
- int n;
- short resid;
- {
- DialogPtr dlog;
- Handle hdl;
- Rect r, bounds;
- Point pt;
- short item, c;
- int i;
- EventRecord event;
- Boolean ok_enabled, rc;
- ListHandle lh;
-
- placewindow( 'DLOG', resid + SELECT_DLOG );
- if (( dlog = GetNewDialog( resid + SELECT_DLOG, (Ptr)NULL, (WindowPtr)-1 )) == NULL ) {
- doalert( ALRT_LOCALERR );
- return( -1 );
- }
- SetPort( dlog );
- ok_enabled = true;
- enablebutton( dlog, DLOG_OK, true, true );
- GetDItem( dlog, DLOG_LIST, &item, &hdl, &r );
- SetDItem( dlog, DLOG_LIST, userItem, (Handle)drawlist, &r );
-
- r.right -= 15;
- SetRect( &bounds, 0, 0, 1, n );
- SetPt( &pt, r.right - r.left, 16 );
-
- if (( lh = LNew( &r, &bounds, pt, 0, (WindowPtr)dlog, false, false, false, true )) == NULL ) {
- return( -1 );
- }
- ((WindowPeek)dlog)->refCon = lh;
- (*lh)->selFlags = lOnlyOne;
- for ( i = 0; i < n; ++i ) {
- SetPt( &pt, 0, i );
- LSetCell( (Ptr)(sl[ i ].sess_name+1), sl[ i ].sess_name[ 0 ], pt, lh );
- }
- SetPt( &pt, 0 , 0 );
- LSetSelect( true, pt, lh );
- LDoDraw( true, lh );
-
- do {
- ModalDialog( (ModalFilterProcPtr)selectfilter, &item );
- SetPt( &pt, 0, 0 );
- rc = LGetSelect( true, &pt, lh );
- if ( !rc && ok_enabled ) {
- enablebutton( dlog, DLOG_OK, false, true );
- ok_enabled = false;
- } else if ( rc && !ok_enabled ) {
- ok_enabled = true;
- enablebutton( dlog, DLOG_OK, true, true );
- }
- } while ( item != DLOG_OK && item != DLOG_CANCEL );
-
- if ( item == DLOG_CANCEL ) {
- LDispose( lh );
- DisposDialog( dlog );
- return( -1 );
- }
- SetPt( &pt, 0, 0 );
- if ( !LGetSelect( true, &pt, lh )) {
- pt.v = -1;
- }
- LDispose( lh );
- DisposDialog( dlog );
- return( pt.v );
- }
-
- pascal void
- drawlist( dlog, item )
- DialogPtr dlog;
- short item;
- {
- short type;
- Handle hdl;
- Rect r;
- ListHandle lh;
-
- if ( item == DLOG_LIST ) {
- GetDItem( dlog, item, &type, &hdl, &r );
- InsetRect( &r, -1, -1 );
- FrameRect( &r );
- lh = (ListHandle) ((WindowPeek)dlog)->refCon;
- HLock( (Handle)lh );
- LUpdate( (*lh)->port->visRgn, lh );
- HUnlock( (Handle)lh );
- }
- }
-
-
- pascal Boolean
- selectfilter( dlog, event, item )
- DialogPtr dlog;
- EventRecord *event;
- short *item;
- {
- char c;
- Point pt;
- short type;
- Rect r;
- Handle hdl;
- ListHandle lh;
-
- lh = (ListHandle) ((WindowPeek)dlog)->refCon;
-
- switch (event->what ) {
- case keyDown:
- case autoKey:
- c = event->message & charCodeMask;
- if ( c == CHAR_ENTER || c == CHAR_RETURN ) {
- GetDItem( dlog, DLOG_OK, &type, &hdl, &r );
- *item = ( type & itemDisable ) ? 0 : DLOG_OK;
- return( true );
- }
- if ( c == CHAR_ESC ) {
- *item = DLOG_CANCEL;
- return( true );
- }
- break;
- case updateEvt:
- if ( event->message == dlog ) { /* for this dialog */
- LUpdate( dlog->visRgn, lh );
- return( false );
- }
- break;
- case mouseDown:
- GetDItem( dlog, DLOG_LIST, &type, &hdl, &r );
- pt = event->where;
- GlobalToLocal( &pt );
- if ( PtInRect( pt, &r )) {
- if ( LClick( pt, event->modifiers, lh )) {
- *item = DLOG_OK;
- }
- return( true );
-
- }
- break;
- }
- return( false );
- }